<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>io.jenkins.jenkinsfile-runner</groupId>
    <artifactId>parent</artifactId>
    <version>${revision}${changelist}</version>
  </parent>

  <artifactId>jenkinsfile-runner</artifactId>

  <build>
    <finalName>jenkinsfile-runner</finalName>
    <plugins>
      <plugin>
         <groupId>org.codehaus.mojo</groupId>
         <artifactId>appassembler-maven-plugin</artifactId>
         <version>2.1.0</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>assemble</goal>
            </goals>
            <configuration>
              <programs>
                <program>
                  <id>jenkinsfile-runner</id>
                  <mainClass>io.jenkins.jenkinsfile.runner.bootstrap.Bootstrap</mainClass>
                </program>
              </programs>
            </configuration>
          </execution>
        </executions>
       </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>prepare-lib</id>
            <phase>package</phase>
            <goals>
              <goal>copy</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>io.jenkins.jenkinsfile-runner</groupId>
                  <artifactId>setup</artifactId>
                  <version>${project.version}</version>
                  <outputDirectory>${project.build.directory}/appassembler/lib/setup</outputDirectory>
                  <destFileName>setup.jar</destFileName>
                </artifactItem>
                <artifactItem>
                  <groupId>io.jenkins.jenkinsfile-runner</groupId>
                  <artifactId>payload</artifactId>
                  <version>${project.version}</version>
                  <outputDirectory>${project.build.directory}/appassembler/lib/payload</outputDirectory>
                  <destFileName>payload.jar</destFileName>
                </artifactItem>
              </artifactItems>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <!-- TODO(oleg_nenashev): Standalone JAR generation works by luck: https://github.com/jenkinsci/jenkinsfile-runner/issues/350
           META-INF definitions are not merged correctly, and extension annotations from the core might be overridden by plugins.
           Custom container description handlers are required to handle META-INF/annotations/hudson.Extension though it might be replaced by META-INF/annotations/hudson.Extension.txt.
           FTR: https://maven.apache.org/plugins/maven-assembly-plugin/examples/single/using-container-descriptor-handlers.html
       -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
          <finalName>jenkinsfile-runner-standalone</finalName>
          <appendAssemblyId>false</appendAssemblyId>
          <archive>
            <manifest>
              <mainClass>io.jenkins.jenkinsfile.runner.bootstrap.Bootstrap</mainClass>
              <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
            </manifest>
          </archive>
        </configuration>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
            <configuration>
              <descriptors>
                <descriptor>src/main/resources/assembly/zip.xml</descriptor>
              </descriptors>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <configuration>
          <resources>
            <resource>
              <directory>src/main/resources-filtered</directory>
              <filtering>true</filtering>
            </resource>
          </resources>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <dependencies>
    <dependency>
      <groupId>io.jenkins.jenkinsfile-runner</groupId>
      <artifactId>bootstrap</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>commons-collections</groupId>
      <artifactId>commons-collections</artifactId>
    </dependency>
    <dependency>
      <groupId>org.jenkins-ci</groupId>
      <artifactId>annotation-indexer</artifactId>
    </dependency>
  </dependencies>
</project>
